#include "led.h"
#include <stdint.h>

// set leds pin
void setLedPin(uint32_t data)
{
    RegWrite(LEDS_GPIO_DATA, data);
}

//id:1~16 max32
//state： 0=灭 ， 1 or else = 亮
void setLedBit(uint8_t led_id, uint8_t state)
{	
	if(led_id < 32)
	{	
		uint32_t led_reg = RegRead(LEDS_GPIO_DATA);
		uint32_t data = 1;
		data = data << (led_id - 1); 
		if(state)
		{
			led_reg = led_reg | data;
		}
		else
		{
			led_reg = led_reg & (~data);
		}
		RegWrite(LEDS_GPIO_DATA, led_reg);
	}
}

// toggle one led pin
void toggleLedPin(uint32_t data)
{
    uint32_t led_data;
    uint32_t process_bit;

    led_data = RegRead(LEDS_GPIO_DATA);
    process_bit = 0x1 << data;

    if(led_data & process_bit)
    {
        led_data = led_data & (~process_bit);
    }
    else
    {
        led_data = led_data | process_bit;
    }

    RegWrite(LEDS_GPIO_DATA,led_data);
}